package com.san.hkhospital.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.entity.Examine;
import com.san.hkhospital.service.ExamineService;
import com.san.hkhospital.service.impl.ExamineServiceImpl;
import com.san.hkhospital.vo.ResultVO;
import com.san.hkhospital.vo.Search1;
import com.san.hkhospital.vo.examineTableVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (examine)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/examine")
public class ExamineController {
/**
* 服务对象
*/
@Resource
private ExamineServiceImpl examineServiceImpl;
@Resource
private ExamineService examineService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping(value = "/{id}")
public ResultVO selectOne(@PathVariable Integer id) {
    Examine examine =examineService.find(id);
    if(examine!=null){
        return ResultVO.success("一个检查单查找成功！",examine);
    }else{
        return ResultVO.failed("一个检查单查找失败！");
    }
 }
    @GetMapping
    public ResultVO examineTableVOList(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<examineTableVO> examineTableVOList = examineService.findAll();
        PageInfo<examineTableVO> pageInfo =new PageInfo<examineTableVO>(examineTableVOList);
        return ResultVO.success("所有检查单查询成功！",pageInfo);
    }
    @PostMapping
    public ResultVO add(@RequestBody Examine examine){
        boolean flag =  examineService.add(examine);
        if(flag){
            return ResultVO.success("添加检查单成功！");
        }else{
            return ResultVO.failed("添加检查单失败！");
        }
    }
    @PutMapping()
    public ResultVO update(@RequestBody Examine examine){
        boolean flag = examineService.update(examine);
        if(flag){
            return ResultVO.success("检查单修改成功！");
        }else{
            return ResultVO.failed("检查单修改失败！");
        }
    }
    @RequestMapping("Search")
    public ResultVO Search(@RequestBody Search1 search1, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<examineTableVO> examineTableVOList = examineService.search(search1);
        PageInfo<examineTableVO> pageInfo =new PageInfo<>(examineTableVOList);
        return ResultVO.success("搜索查询成功！",pageInfo);
    }

}
